/*
 * @Author: fah 1742484532@qq.com
 * @Date: 2024-09-12 15:03:47
 * @LastEditors: fah 1742484532@qq.com
 * @LastEditTime: 2024-09-13 15:28:20
 * @FilePath: \livetree-admin-server\src\lives\lives.service.ts
 * @Description: 指飞部-企业数字化管理系统
 * @version: 1.0
 */
import { Injectable } from '@nestjs/common';
import { CreateLifeDto } from './dto/create-live.dto';
import { UpdateLifeDto } from './dto/update-live.dto';
import { Live } from './entities/live.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { QueryLifeDto } from './dto/query-live.dto';
import { responseMessage } from 'src/utils';

@Injectable()
export class LivesService {
  constructor(
    @InjectRepository(Live)
    private readonly liveRepository,
  ) {}

  create(createLifeDto: CreateLifeDto) {
    const live = new Live();
    live.title = createLifeDto.title;
    live.content = createLifeDto.content;

    return this.liveRepository.save(live);
  }

  async getLiveList(query: QueryLifeDto) {
    const entity = this.liveRepository.createQueryBuilder('live');
    entity.skip(query.size * (query.page - 1)).take(query.size);
    entity.orderBy('live.create_time', 'DESC');
    const [list, total] = await entity.getManyAndCount();
    return responseMessage({ list, total });
  }

  findOne(id: number) {
    return `This action returns a #${id} life`;
  }

  update(id: number, updateLifeDto: UpdateLifeDto) {
    return `This action updates a #${id} life`;
  }

  remove(id: number) {
    return `This action removes a #${id} life`;
  }
}
